# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: http://doc.scrapy.org/topics/item-pipeline.html
from PIL import Image
from items import buyItem,amazonItem
class FinallproPipeline():
    def process_item(self, item, spider):
        return item

class buy():
	def process_item(self,item,spider):
		
		if isinstance(item,buyItem):
			type='360'
			update(item,type)
			return item
		elif isinstance(item,amazonItem):
			type='amazon'
			update(item,type)
			return item
		else:
			#this is for dangdang
			type='dangdang'
			update(item,type)
			return item
def update(item,type):
	import pymongo
	#import MySQLdb
	#conn=MySQLdb.connect(host='',user='root',passwd='weihong',db='audoe',charset='utf8')
	#cur=conn.cursor()
	title=item['title']
	id=item['id']
	price=item['price']
	img=item['img']
	conn=pymongo.Connection('mongodb://audoe:weihong@mongoc2.grandcloud.cn:10003/fg')
	db=conn.fg
	table=db.table
	table.insert({'id':id,'title':title,'price':price,
					'img':img})
	#cur.execute('insert into tmp values(%s,%s,%s,%s,%s)',(title,id,type,price,img))
	#conn.commit()
	#cur.close()
	#conn.close()
